package com.dididoctor.doctor.Activity.PatientDetial;

import android.content.Context;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Http.MyHttpResponseHandler;
import com.dididoctor.doctor.MV.BasePresenter;
import com.dididoctor.doctor.MV.BusinessClient;
import com.dididoctor.doctor.MV.Response;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.Map;

/**
 * @version 2.0
 * @类描述： 登陆页
 * @项目名称：ddgh
 * @类名称： loginActivity
 * @包名称： com.doudoukeji.service.Activity.login
 * @创建人：张强 boy
 * @创建时间：2016/3/7 16:40
 * @修改人：
 * @修改时间：2016/3/7 16:40
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class PersonalDataPresenter extends BasePresenter {
    private PersonalDataView view;

    public PersonalDataPresenter(Context context, PersonalDataView view) {
        super(context, view);
        this.view = view;
    }

    public void Lunch(String clientId) {
//        userId	String	是	用户
//        token	String	是
//        clientId	String	是	患者id
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        params.put("clientId", clientId);
        BusinessClient.post(ConstantValue.clientInfoUrl, params, new MyHttpResponseHandler(view) {
            private PersonalDataBean personal = new PersonalDataBean();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    Map<String, Object> data = response.getMap("data");
//                "name":"1",//姓名
//                    "age":"1",//患者年龄
//                            "sex":"",//性别0-女，1-男
//                    “headPic”:””//头像
//                    "job":"",//职业
//                            "allergicPill":"",//过敏药品
//                            "allergicFood":"",//过敏食物
                    personal.setName(response.getString("name")+"");
                    personal.setAge(response.getString("age")+"");
                    personal.setSex(response.getString("sex")+"");
                    personal.setHeadPic(response.getString("headPic")+"");
                    personal.setJob(response.getString("job")+"");
                    personal.setAllergicPill(response.getString("allergicPill")+"");
                    personal.setAllergicFood(response.getString("allergicFood")+"");
                    view.getdoctorsucced(personal);
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getdoctorfail();
            }
        });
    }
}
